/**
* \file DGVTable.h
*
* \brief This file defines the class for display data using tables using only Qt.
* \author Shekhar S. Chandra, 2008
*
* This file is part of DGV Library.
*
* DGV is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DGV is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DGV.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DGVTABLE_H
#define DGVTABLE_H

#include <QtGui/QTableWidget> //For Base Class
#include <QtGui/QtGui>

#include "DGVPlot.h"
//#include "DGVAnimate.h"

typedef double tableType;

/*!
    \class DGVTable
    \brief This class handles display of data in a table using Qt. WORK IN PROGESS.
    \author Shekhar S. Chandra, 2008

    It uses the QTableWidget to display Blitz++ arrays and also reads CSV files.
*/
class DGV_EXPORT DGVTable : public QTableWidget
{
    Q_OBJECT

public:
    /*!
        \fn DGVTable::DGVTable(QWidget *parent = 0)
        \brief The standard constructor
    */
    DGVTable(QWidget *parent = 0);
    /*!
        \fn DGVTable::~DGVTable()
        \brief The standard destructor
    */
    virtual ~DGVTable();
    /*!
        \fn DGVTable::setName(QString filename)
        \brief Set the name of the table.
    */
    void setName(QString filename);
    /*!
        \fn DGVTable::setItem(int row, int column, tableType value)
        \brief Sets the value into table at position. Automates item creation etc.
    */
    virtual void setItem(int row, int column, tableType value);
    virtual void setItem(int row, int column, QString value);
    /*!
        \fn DGVTable::getItem(int x, int y)
        \brief Returns the data at (x,y) in the table.
    */
    tableType getItem(int x, int y);

    /*!
        \fn DGVTable::loadCSV(const QString filename)
        \brief Loads the CSV file into table. Returns true if successful.
    */
    bool loadCSV(const QString filename);
    /*!
        \fn DGVTable::setData(Array<tableType,2> &values)
        \brief Sets table up for values provided.
    */
    void setData(Array<tableType,2> &values);
    /*!
        \fn DGVTable::data()
        \brief Returns a Blitz++ array containing the table data.
    */
    Array<tableType,2>& data();

    /*!
        \fn DGVTable::data()
        \brief Clears the internal Blitz++ array containing the table data.
    */
    inline void clearArray()
    {   tableData.free();  }
    /*!
        \fn DGVTable::strippedName()
        \brief Returns the stripped (path removed) name of the table.
	*/
	QString strippedName();
	/*!
        \fn DGVTable::strippedNamePrefix()
        \brief Returns the stripped (path removed) name of the table with "Table" prefix.
	*/
	QString strippedNamePrefix();

public slots:
    /*!
        \fn DGVTable::zapSelection()
        \brief Sets the selection to zero.
    */
    void zapSelection();
    /*!
        \fn DGVTable::delSelection()
        \brief Deletes the selection.
    */
    void delSelection();
    /*!
        \fn DGVTable::plotSelection()
        \brief Plots the selection.
    */
    void plotSelection();
    /*!
        \fn DGVTable::scanSelection()
        \brief Scans through the selection using line plot.
    */
    void scanSelection();
    /*!
        \fn DGVTable::saveSelection()
        \brief Save the selection using CSV file.
    */
    void saveSelection();
    /*!
        \fn DGVTable::saveAll()
        \brief Save the entire table using CSV file.
    */
    void saveAll();

signals:
    /*!
        \fn DGVTable::plotAvailable(DGVPlot *)
        \brief Send signal that a plot is available for showing.
    */
    void plotAvailable(DGVPlot *);
    /*!
        \fn DGVTable::animAvailable(DGVAnimate *)
        \brief Send signal that a plot is available for showing.
    */
    //void animAvailable(DGVAnimate *);

protected:
    QString name; //!< Name of the table (with full path)

    QAction *zapAct; //!< Action object for zapping a selection.
    QAction *delAct; //!< Action object for deleting a selection.
    //-------------
    QAction *plotAct; //!< Action object for plotting a selection.
    QAction *scanAct; //!< Action object for scanning through a selection.
    //-------------
    QAction *saveAct; //!< Action object for saving the selection.
    QAction *saveAllAct; //!< Action object for saving entire table.
    QAction *closeAct; //!< Action object for closing the table.
    //QVector<QTableWidgetItem*> tableItems; //!< Maintains the actual table items.

    Array<tableType,2> tableData; //!< Array. Empty until data() is called. Then it is assumed that DGVImage is not used and is created.

    /*!
        \fn DGVTable::contextMenuEvent(QContextMenuEvent *event)
        \brief The context menu setup member
    */
    virtual void contextMenuEvent(QContextMenuEvent *event);
    /*!
        \fn DGVTable::createConnections()
        \brief Sets up the connections between widgets.
    */
    void createConnections();
};



#endif // DGVTABLE_H
